//
//  DBAnimate.cpp
//  DragonBonesCPP
//
//  Created by DuanHongbo on 15/1/19.
//
//

#include "DBAnimate.h"

DRAGONBONES_NAMESPACE_BEGIN

DBAnimate* DBAnimate::create(float duration,const std::string& aniName)
{
    DBAnimate *animate = new (std::nothrow) DBAnimate();
    animate->init(duration,aniName);
    animate->autorelease();
    
    return animate;
}

DBAnimate::DBAnimate()
:_armatureNode(nullptr)
{
    
}

DBAnimate::~DBAnimate()
{
    
}

bool DBAnimate::init(float duration,const std::string& aniName)
{
    this->_aniName = aniName;
    if ( ActionInterval::initWithDuration(duration))
    {
        return true;
    }
    return false;
}


DBAnimate* DBAnimate::clone() const
{
    // no copy constructor
    auto a = new (std::nothrow) DBAnimate();
    a->init(this->_duration,this->_aniName);
    a->autorelease();
    return a;
}

void DBAnimate::update(float t)
{
    
}

void DBAnimate::startWithTarget(Node *target)
{
    ActionInterval::startWithTarget(target);
    auto armatureNode = dynamic_cast<CCArmatureDisplay*>(target);
    armatureNode->getArmature()->getAnimation()->play(_aniName);
}

void DBAnimate::stop()
{
    auto armatureNode = dynamic_cast<CCArmatureDisplay*>(getTarget());
    if(armatureNode)
    {
        armatureNode->getArmature()->getAnimation()->stop(_aniName);
    }
    ActionInterval::stop();
}

DRAGONBONES_NAMESPACE_END
